package com.lotter.api.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lotter.api.service.StatisticsIncomeService;
import com.lotter.invocation.StaticDataContext;
import com.lotter.model.statistics.StatisticsIncomeDay;
import com.lotter.model.statistics.StatisticsIncomeMonth;
import com.lotter.model.statistics.StatisticsIncomeYear;

/**
 * 房间盈利  
 * @author zhangzechi
 */
@Controller
@RequestMapping(value="/website/profit")
public class HouserProfitController extends BaseController {
	

	
	@Autowired
	private StatisticsIncomeService incomeService ;
	
	
	/**
	 * 房间盈利  --本年
	 * @param request
	 * @param vo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/year" ,method = RequestMethod.GET)
	public Map<String,Object> year(@RequestParam(value ="token",required = true) String token) {
		Map<String,Object> result = new HashMap<String, Object>();
		try {
			Long uid = StaticDataContext.onLineUid(token);
			StatisticsIncomeYear statisticsIncomeYear = incomeService.findYearEntity(uid) ;
			if(statisticsIncomeYear != null){
				result.put("statisticsIncomeYear", statisticsIncomeYear);
				List<StatisticsIncomeMonth> list = incomeService.findMonthList(statisticsIncomeYear.getId());
				result.put("monthList", list);
			}
		} catch (Exception e) {
			logger.error("查询有误，请检查代码");
			return ajaxLotterServer("查收出错,请联系管理员");
		}
		return ajaxLotterSuccess(result);
	}
	
	
	
	/**
	 * 房间盈利  --月份
	 * @param request
	 * @param vo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/month" ,method = RequestMethod.GET)
	public Map<String,Object> month(@RequestParam(value ="token",required = true) String token) {
		Map<String,Object> result = new HashMap<String, Object>();
		try {
			Long uid = StaticDataContext.onLineUid(token);
			StatisticsIncomeMonth statisticsIncomeMonth = incomeService.findMonthEntity(uid) ;
			if(statisticsIncomeMonth != null){
				result.put("statisticsIncomeMonth", statisticsIncomeMonth);
				List<StatisticsIncomeDay> list = incomeService.findDayList(statisticsIncomeMonth.getId());
				result.put("dayList", list);
			}
		} catch (Exception e) {
			logger.error("查询有误，请检查代码");
			return ajaxLotterServer("查收出错,请联系管理员");
		}
		return ajaxLotterSuccess(result);
	}

}
